using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using PetShop.Domain.Model;
using PetShop.Application.Facade;

namespace PetShop.Web {
	public class ItemDetails : Page {
		
		private const string MSG_BACK_ORDERED = "Back Ordered";
		private const string CSS_ALERT = "alert";

		protected ItemEntity itemInfo;
		protected PetShop.Web.Controls.NavBar header;
		protected Label lblQty;
		protected Label lblDescription;
		protected Label lblName;
		protected Label lblProductName;
		protected Label lblPrice;
		protected Label lblSearchResults;

		private void InitializeComponent() {}

		override protected void OnLoad(EventArgs e) {

			
			string itemId = WebComponents.CleanString.InputText(Request["itemId"], 50);

			
            CatalogFC catalog = new CatalogFC();

			
			itemInfo = catalog.GetItemInfoByID(itemId);

			
			if(itemInfo != null){

				lblDescription.Text = itemInfo.Description;
				lblName.Text = itemInfo.Id;
				lblProductName.Text = itemInfo.Product.Name;
				lblPrice.Text = itemInfo.ListPrice.ToString();
			
				
				if (itemInfo.InventoryQty > 0)
                    lblQty.Text = itemInfo.InventoryQty.ToString();
				else {
					lblQty.Text = MSG_BACK_ORDERED;
					lblQty.CssClass = CSS_ALERT;
				}
			}else{
				lblSearchResults.Text = "Item not found";
			}
		}
	}
}